From: Jeroen van der Heijden Date: Thu, 9 Apr 2020 13:49:03 +0000 (+0200) Subject: Start work on evars X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~3^2~5^2~5 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=d9cb4c4f1080a24601c755cf428e207141ab6086;p=siridb-server.git Start work on evars --- diff --git a/include/siri/evars.h b/include/siri/evars.h new file mode 100644 index 00000000..147974d4 --- /dev/null +++ b/include/siri/evars.h @@ -0,0 +1,11 @@ +/* + * siri/evars.h + */ +#ifndef SIRI_EVARS_H_ +#define SIRI_EVARS_H_ + +#include + +void siri_evars_parse(siri_t * siri); + +#endif /* SIRI_EVARS_H_ */ diff --git a/main.c b/main.c index 819a4f14..0ee8e746 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,8 @@ int main(int argc, char * argv[]) /* read siridb main application configuration */ siri_cfg_init(&siri); + siri_evars_parse(&siri); + /* start SiriDB. (this start the event loop etc.) */ if (siri_start() && !siri_err) { diff --git a/src/siri/cfg/cfg.c b/src/siri/cfg/cfg.c index 9a6c8b47..8bb840b5 100644 --- a/src/siri/cfg/cfg.c +++ b/src/siri/cfg/cfg.c @@ -633,8 +633,10 @@ static void SIRI_CFG_read_address_port( siri.args->config, cfgparser_errmsg(rc)); exit(EXIT_FAILURE); + return; } - else if (option->tp != CFGPARSER_TP_STRING) + + if (option->tp != CFGPARSER_TP_STRING) { log_critical( "Error reading '%s' in '%s': %s. ", @@ -642,80 +644,78 @@ static void SIRI_CFG_read_address_port( siri.args->config, "error: expecting a string value"); exit(EXIT_FAILURE); + return; } - else - { - if (*option->val->string == '[') - { - /* an IPv6 address... */ - for (port = address = option->val->string + 1; *port; port++) - { - if (*port == ']') - { - *port = 0; - port++; - break; - } - } - } - else - { - port = address = option->val->string; - } - for (; *port; port++) + if (*option->val->string == '[') + { + /* an IPv6 address... */ + for (port = address = option->val->string + 1; *port; port++) { - if (*port == ':') + if (*port == ']') { *port = 0; port++; break; } } + } + else + { + port = address = option->val->string; + } + + for (; *port; port++) + { + if (*port == ':') + { + *port = 0; + port++; + break; + } + } + + if ( !strlen(address) || + strlen(address) >= SIRI_CFG_MAX_LEN_ADDRESS || + !xstr_is_int(port) || + strcpy(address_pt, address) == NULL || + xstr_replace_str( + address_pt, + "%HOSTNAME", + hostname, + SIRI_CFG_MAX_LEN_ADDRESS)) + { + log_critical( + "Error reading '%s' in '%s': " + "error: got an unexpected value '%s:%s'.", + option_name, + siri.args->config, + address, + port); + exit(EXIT_FAILURE); + } + else + { + test_port = atoi(port); - if ( !strlen(address) || - strlen(address) >= SIRI_CFG_MAX_LEN_ADDRESS || - !xstr_is_int(port) || - strcpy(address_pt, address) == NULL || - xstr_replace_str( - address_pt, - "%HOSTNAME", - hostname, - SIRI_CFG_MAX_LEN_ADDRESS)) + if (test_port < 1 || test_port > 65535) { log_critical( "Error reading '%s' in '%s': " - "error: got an unexpected value '%s:%s'.", + "error: port should be between 1 and 65535, got '%d'.", option_name, siri.args->config, - address, - port); + test_port); exit(EXIT_FAILURE); } else { - test_port = atoi(port); - - if (test_port < 1 || test_port > 65535) - { - log_critical( - "Error reading '%s' in '%s': " - "error: port should be between 1 and 65535, got '%d'.", - option_name, - siri.args->config, - test_port); - exit(EXIT_FAILURE); - } - else - { - *port_pt = (uint16_t) test_port; - } - - log_debug("Read '%s' from config: %s:%d", - option_name, - address_pt, - *port_pt); + *port_pt = (uint16_t) test_port; } + log_debug("Read '%s' from config: %s:%d", + option_name, + address_pt, + *port_pt); } } diff --git a/src/siri/db/auth.c b/src/siri/db/auth.c index 7144815c..d0b4a3bb 100644 --- a/src/siri/db/auth.c +++ b/src/siri/db/auth.c @@ -42,7 +42,18 @@ cproto_server_t siridb_auth_user_request( username, password)) == NULL) { - log_warning("User authentication request failed: invalid credentials"); + if (strcmp(username, "sa") == 0) + { + log_warning( + "User authentication request failed: " + "invalid credentials for user `sa`, " + "did you mean to use the default database user `iris`?"); + } + else + { + log_warning( + "User authentication request failed: invalid credentials"); + } return CPROTO_ERR_AUTH_CREDENTIALS; } diff --git a/src/siri/evars.c b/src/siri/evars.c new file mode 100644 index 00000000..480939f8 --- /dev/null +++ b/src/siri/evars.c @@ -0,0 +1,57 @@ +/* + * siri/evars.c + */ + +#include + +static void evars__u8(const char * evar, uint8_t * u8) +{ + char * u8str = getenv(evar); + if (!u8str) + return; + + *u8 = (uint8_t) strtoul(u8str, NULL, 10); +} + +static void evars__u16(const char * evar, uint16_t * u16) +{ + char * u16str = getenv(evar); + if (!u16str) + return; + + *u16 = (uint16_t) strtoul(u16str, NULL, 10); +} + +static void evars__sizet(const char * evar, size_t * sz) +{ + char * sizetstr = getenv(evar); + if (!sizetstr) + return; + + *sz = (size_t) strtoull(sizetstr, NULL, 10); +} + +static void evars__double(const char * evar, double * d) +{ + char * doublestr = getenv(evar); + if (!doublestr) + return; + + *d = strtod(doublestr, NULL); +} + +static void evars__str(const char * evar, char ** straddr) +{ + char * str = getenv(evar); + if (!str || !(str = strdup(str))) + return; + + free(*straddr); + *straddr = str; +} + + +void siri_evars_parse(siri_t * siri) +{ + +} diff --git a/src/siri/net/tcp.c b/src/siri/net/tcp.c index dd3c5fe6..2cdcc070 100644 --- a/src/siri/net/tcp.c +++ b/src/siri/net/tcp.c @@ -85,6 +85,83 @@ failed: } +int sirinet_extract_addr_port( + const char * s, + char * addr, + uint16_t * port) +{ + if (*option->val->string == '[') + { + /* an IPv6 address... */ + for (port = address = option->val->string + 1; *port; port++) + { + if (*port == ']') + { + *port = 0; + port++; + break; + } + } + } + else + { + port = address = option->val->string; + } + + for (; *port; port++) + { + if (*port == ':') + { + *port = 0; + port++; + break; + } + } + + if ( !strlen(address) || + strlen(address) >= SIRI_CFG_MAX_LEN_ADDRESS || + !xstr_is_int(port) || + strcpy(address_pt, address) == NULL || + xstr_replace_str( + address_pt, + "%HOSTNAME", + hostname, + SIRI_CFG_MAX_LEN_ADDRESS)) + { + log_critical( + "Error reading '%s' in '%s': " + "error: got an unexpected value '%s:%s'.", + option_name, + siri.args->config, + address, + port); + exit(EXIT_FAILURE); + } + else + { + test_port = atoi(port); + + if (test_port < 1 || test_port > 65535) + { + log_critical( + "Error reading '%s' in '%s': " + "error: port should be between 1 and 65535, got '%d'.", + option_name, + siri.args->config, + test_port); + exit(EXIT_FAILURE); + } + else + { + *port_pt = (uint16_t) test_port; + } + + log_debug("Read '%s' from config: %s:%d", + option_name, + address_pt, + *port_pt); + } +}